# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libyaml
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.1.6
pkgrel=2
pkgdesc="YAML 1.1 library (mingw-w64)"
arch=('any')
url="http://pyyaml.org/wiki/LibYAML"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('staticlibs' 'strip')
source=(${_realname}-${pkgver}.tar.bz2::https://bitbucket.org/xi/libyaml/get/${pkgver}.tar.bz2
        "0001-Proper-mingw-YAML_DECLARE-definition.patch"
        "0002-libyaml-no-undefined.patch")
sha256sums=('e0fce68d0fdf9742316ad896a1ea1e5e920c54eac643cb0bcb18ac5d13719690'
            'b3c137a1d44432edc35e571b479a0f3f0315f664c994ea147f9c4a7167a9857c'
            '6e26d8ac24052239a1bc2db7e8d9cc28ece490a09c36479ca0209ee890ce387d')

prepare() {
  cd ${srcdir}/xi-libyaml-*
  patch -Np1 -i "$srcdir/0001-Proper-mingw-YAML_DECLARE-definition.patch"
  patch -Np1 -i "$srcdir/0002-libyaml-no-undefined.patch"

  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ../xi-libyaml-*/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
